#include "CEUtilities.h"

#include "CEKeyboard.h"


Keyboard* Keyboard::c_Keyboard = NULL;


//----------------------------------------------------------------------
Keyboard::Keyboard()
{
}


//----------------------------------------------------------------------
Keyboard::~Keyboard()
{
}


//----------------------------------------------------------------------
Keyboard* Keyboard::GetSingleton()
{
	if (!c_Keyboard)
	{
		c_Keyboard = new Keyboard();
	}

	return c_Keyboard;
}


//----------------------------------------------------------------------
BOOL Keyboard::OnCreateKeyboard(HWND hwnd)
{
	return OnCreateDevice(hwnd, GUID_SysKeyboard, &c_dfDIKeyboard, KeyboardBufferSize);
}


//----------------------------------------------------------------------
BOOL Keyboard::IsKeyboardKeyDown(int type, BOOL lastSensitive)
{
	return IsKeyDown(m_KeyState,m_OldKeyState,type,lastSensitive);
}


//----------------------------------------------------------------------
BOOL Keyboard::IsKeyboardKeyUp(int type, BOOL lastSensitive)
{
	return IsKeyDown(m_KeyState,m_OldKeyState,type,lastSensitive);
}


//----------------------------------------------------------------------
BOOL Keyboard::Update(HWND hwnd)
{
	HRESULT	hr;

    if(_SaveState2Old(m_KeyState,m_OldKeyState,KeyboardBufferSize))
	{
		hr = m_pDevice->GetDeviceState(sizeof(m_KeyState), m_KeyState);
	}
	else
	{
		return FALSE;
	}

    return _CheckState(hr);
}